home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Jims CDEFs 1.50 / CDEF Source / source / miscCDEF.c < prev    next >
Encoding:
Text File  |  1995-11-08  |  4.7 KB  |  165 lines  |  [TEXT/KAHL]

  1. //------------------------- © 1994-1995 by James G. Stout --------------------------
  2. // File        : miscCDEF.c
  3. // Date        : November 2,1991
  4. // Author    : Jim Stout
  5. // Purpose    : support routines for CDEFs.
  6. //----------------------------------------------------------------------------------
  7.  
  8. #include <Controls.h>
  9. #include <GestaltEqu.h>
  10. #include <OSUtils.h>
  11. #include <QDOffscreen.h>
  12. #include <ToolUtils.h>
  13. #include <Traps.h>
  14. #include <Types.h>
  15.  
  16. #include "miscCDEF.h"
  17.  
  18. //==================================================================================
  19. //    Get the lowest pixel depth of any GDevice for rect 'r'
  20. //==================================================================================
  21. short getPixDepth(Rect *r)
  22. {
  23.     Rect        gRect, iRect;
  24.     GDHandle     gDev;
  25.     short        thisDepth, pixDepth = 32;
  26.     GrafPtr        thisPort;
  27.     
  28.     GetPort(&thisPort);
  29.     if((thisPort->portBits.rowBytes & 0x8000) == 0)        // b&w port
  30.         return(1);
  31.     
  32.     if(!trapAvailable(_GetDeviceList))                    // Must have Device Mgr
  33.         return(1);                                        // or we draw in 1 bit mode.
  34.         
  35.     gRect = *r;
  36.     
  37.     LocalToGlobal((Point *)&gRect.top);
  38.     LocalToGlobal((Point *)&gRect.bottom);
  39.     
  40.     gDev = GetDeviceList();                                // walk device list looking
  41.     while(gDev) {                                        // for lowest pixDepth
  42.         if(SectRect(&gRect, &(*gDev)->gdRect, &iRect) &&
  43.             TestDeviceAttribute(gDev,screenDevice) &&
  44.             TestDeviceAttribute(gDev,screenActive)) {
  45.             
  46.             thisDepth = (*(*gDev)->gdPMap)->pixelSize;
  47.             if(thisDepth < pixDepth)
  48.                 pixDepth = thisDepth;
  49.         }
  50.         gDev = GetNextDevice(gDev);
  51.     }
  52.     return(pixDepth);
  53. }
  54. //==================================================================================
  55. //    A "simple minded" version of DeviceLoop that will suffice for these CDEFs
  56. //==================================================================================
  57.  
  58. extern void sys6DeviceLoop(RgnHandle drawingRgn, DeviceLoopDrawingUPP drawingProc, 
  59.                                 long userData, DeviceLoopFlags flags)
  60. {
  61.  
  62. #pragma unused(flags)
  63.  
  64.     Rect            gRect, intersect;
  65.     GDHandle         gDev=0;
  66.     RgnHandle        oldClip;
  67.     short            thisDepth;
  68.     devLoopHandle    hDl;
  69.  
  70.     hDl = (devLoopHandle)userData;
  71.  
  72.     oldClip = NewRgn();
  73.     GetClip(oldClip);
  74.  
  75.     if(trapAvailable(_GetDeviceList)) {                        // Must have Device Mgr
  76.         
  77.         gRect = (**hDl).controlRect;                        // need control rect in
  78.         LocalToGlobal((Point *)&gRect.top);                    // global coords
  79.         LocalToGlobal((Point *)&gRect.bottom);
  80.         
  81.         gDev = GetDeviceList();                                // walk device list
  82.         while(gDev) {                                        // and find any that
  83.                                                             // intersect with control
  84.             if(SectRect(&gRect, &(*gDev)->gdRect, &intersect) &&
  85.                 TestDeviceAttribute(gDev,screenDevice) &&
  86.                 TestDeviceAttribute(gDev,screenActive)) {
  87.                 
  88.                 GlobalToLocal((Point *)&intersect.top);
  89.                 GlobalToLocal((Point *)&intersect.bottom);
  90.         
  91.                 ClipRect(&intersect);                        // clip to intersection
  92.                 
  93.                 thisDepth = (*(*gDev)->gdPMap)->pixelSize;
  94.                 
  95.                 CallDeviceLoopDrawingProc(drawingProc, thisDepth, 0, gDev, userData);
  96.             }
  97.             gDev = GetNextDevice(gDev);
  98.         }
  99.     }
  100.     else {                                                    // draw 1 bit version
  101.         SetClip(drawingRgn);
  102.         CallDeviceLoopDrawingProc(drawingProc, 1, 0, gDev, userData);
  103.     }
  104.     SetClip(oldClip);
  105.     DisposeRgn(oldClip);
  106. }
  107.  
  108. //==================================================================================
  109. //    Use Gestalt to find out the MacOS version. 
  110. //==================================================================================
  111. short getOSVers()
  112. {
  113.     OSErr        err;
  114.     short        ret=0x0600;
  115.     long        gResult;
  116.     
  117.     if(trapAvailable(_Gestalt)) {                        // is Gestalt available ?    
  118.         err = Gestalt(gestaltSystemVersion,&gResult);
  119.         if(err == noErr)
  120.             ret = LoWord(gResult);
  121.     }
  122.     return(ret);
  123. }
  124. //==================================================================================
  125. //    Generic routine to see if a given trap is available
  126. //==================================================================================
  127.  
  128. Boolean    trapAvailable(short theTrap)
  129. {
  130.     TrapType    tType;
  131.     
  132.     tType = getTrapType(theTrap);
  133.     
  134.     if(tType == ToolTrap) {
  135.         theTrap &= 0x07ff;
  136.         if(theTrap >= numToolBoxTraps())
  137.             theTrap = _Unimplemented;
  138.     }
  139.     return(( NGetTrapAddress(theTrap, tType) !=
  140.         NGetTrapAddress(_Unimplemented, ToolTrap) ));
  141. }
  142.  
  143. //==================================================================================
  144. //    Needed for "trapAvailable" routine
  145. //==================================================================================
  146.  
  147. TrapType getTrapType(short theTrap)
  148. {
  149.     if((theTrap &= 0x0800))
  150.         return(ToolTrap);
  151.     return(OSTrap);
  152. }
  153.  
  154. //==================================================================================
  155. //    Needed for "trapAvailable" routine
  156. //==================================================================================
  157.  
  158. short numToolBoxTraps()
  159. {
  160.     if(NGetTrapAddress(_InitGraf, ToolTrap) ==
  161.         NGetTrapAddress(0xaa6e, ToolTrap))
  162.         return(0x0200);
  163.     return(0x0400);
  164. }
  165.